﻿// CDialogDIO.cpp: 实现文件
//
#include "stdafx.h"
//#include "pch.h"
#include "DefectInspectionSystem.h"
#include "CDialogDIO.h"
#include "afxdialogex.h"
#include "DefectInspectionSystemDlg.h"

// CDialogDIO 对话框

IMPLEMENT_DYNAMIC(CDialogDIO, CDialogEx)

CDialogDIO::CDialogDIO(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG6, pParent)
{
	/*m_BlowDelay1 = 50;
	m_BlowContinue1 = 300;
	m_BlowDelay2 = 50;
	m_BlowContinue2 = 300;*/
}

CDialogDIO::~CDialogDIO()
{
}

void CDialogDIO::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDialogDIO, CDialogEx)
	ON_BN_CLICKED(IDOK, &CDialogDIO::OnBnClickedOk)
	//	ON_WM_CREATE()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_CHECK_DoubleBox, &CDialogDIO::OnBnClickedCheckDoublebox)
END_MESSAGE_MAP()


// CDialogDIO 消息处理程序


void CDialogDIO::OnBnClickedOk()
{
	CDefectInspectionSystemDlg* pDia = CDefectInspectionSystemDlg::s_pDialog;
	CString tmpstr;
	theApp.m_Abs_Sensor12 = GetDlgItemInt(IDC_EDIT_ABS_SENSOR12);
	theApp.m_Abs_Sensor23 = GetDlgItemInt(IDC_EDIT_ABS_SENSOR23);
	theApp.m_BlowDelay1 = GetDlgItemInt(IDC_EDIT_BlowDelay);
	theApp.m_BlowDelay2 = GetDlgItemInt(IDC_EDIT_BlowDelay2);
	theApp.m_BlowContinue1 = GetDlgItemInt(IDC_EDIT_BlowContinue);
	theApp.m_BlowContinue2 = GetDlgItemInt(IDC_EDIT_BlowContinue2);
	theApp.appDifferenceCamSensor = GetDlgItemInt(IDC_EDIT_ABS_CAM_SENSOR);
	tmpstr.Format("%d", theApp.m_BlowDelay1);
	WritePrivateProfileString("DIO", "BlowDelay1", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	tmpstr.Format("%d", theApp.m_BlowDelay2);
	WritePrivateProfileString("DIO", "BlowDelay2", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	tmpstr.Format("%d", theApp.m_BlowContinue1);
	WritePrivateProfileString("DIO", "BlowContinue1", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	tmpstr.Format("%d", theApp.m_BlowContinue2);
	WritePrivateProfileString("DIO", "BlowContinue2", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	tmpstr.Format("%d", theApp.appDifferenceCamSensor);
	WritePrivateProfileString("DIO", "DifferenceCamSensor", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");


	tmpstr.Format("%d", theApp.m_Abs_Sensor12);
	WritePrivateProfileString("DIO", "Abs_Sensor12", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	tmpstr.Format("%d", theApp.m_Abs_Sensor23);
	WritePrivateProfileString("DIO", "Abs_Sensor23", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");

	tmpstr.Format("%d", theApp.m_bIsDoubleBox==true?1:0);
	WritePrivateProfileString("DIO", "DoubleBox", tmpstr, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	
	CDialogEx::OnOK();
}



BOOL CDialogDIO::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	CDefectInspectionSystemDlg* pDia = CDefectInspectionSystemDlg::s_pDialog;
	char tmpstr[MAX_PATH];
	CString strTemp;
	GetPrivateProfileString("DIO", "BlowDelay1", "10", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.m_BlowDelay1 = atoi(tmpstr);
	GetPrivateProfileString("DIO", "BlowDelay2", "10", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.m_BlowDelay2 = atoi(tmpstr);
	GetPrivateProfileString("DIO", "BlowContinue1", "100", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.m_BlowContinue1 = atoi(tmpstr);
	GetPrivateProfileString("DIO", "BlowContinue2", "100", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.m_BlowContinue2 = atoi(tmpstr);
	GetPrivateProfileString("DIO", "DifferenceCamSensor", "2", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.appDifferenceCamSensor = atoi(tmpstr);

	GetPrivateProfileString("DIO", "DoubleBox", "0", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.m_bIsDoubleBox = (atoi(tmpstr)==0?false:true);
	if (theApp.m_bIsDoubleBox)
	{
		((CButton*)GetDlgItem(IDC_CHECK_DoubleBox))->SetCheck(TRUE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_CHECK_DoubleBox))->SetCheck(FALSE);
	}
	SetDlgItemInt(IDC_EDIT_BlowDelay, theApp.m_BlowDelay1);
	SetDlgItemInt(IDC_EDIT_BlowDelay2, theApp.m_BlowDelay2);
	SetDlgItemInt(IDC_EDIT_BlowContinue, theApp.m_BlowContinue1);
	SetDlgItemInt(IDC_EDIT_BlowContinue2, theApp.m_BlowContinue2);
	SetDlgItemInt(IDC_EDIT_ABS_CAM_SENSOR, theApp.appDifferenceCamSensor);

	GetPrivateProfileString("DIO", "Abs_Sensor12", "2", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.m_Abs_Sensor12 = atoi(tmpstr);
	GetPrivateProfileString("DIO", "Abs_Sensor23", "3", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	theApp.m_Abs_Sensor23 = atoi(tmpstr);
	SetDlgItemInt(IDC_EDIT_ABS_SENSOR12, theApp.m_Abs_Sensor12);
	SetDlgItemInt(IDC_EDIT_ABS_SENSOR23, theApp.m_Abs_Sensor23);
	SetTimer(1, 500, NULL);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CDialogDIO::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	SetDlgItemInt(IDC_EDIT_Sensor1, theApp.appSensor1);
	SetDlgItemInt(IDC_EDIT_Sensor2, theApp.appSensor2);
	SetDlgItemInt(IDC_EDIT_Sensor3, theApp.appSensor3);
	SetDlgItemInt(IDC_EDIT_SensorTG ,theApp.appSensorTG);
	SetDlgItemInt(IDC_EDIT_Cam1, theApp.appVisionFront);
	SetDlgItemInt(IDC_EDIT_Cam2, theApp.appVisionBack);
	SetDlgItemInt(IDC_EDIT_CamTG, theApp.appVisionTG);
	CDialogEx::OnTimer(nIDEvent);
}


void CDialogDIO::OnBnClickedCheckDoublebox()
{
	if (((CButton*)GetDlgItem(IDC_CHECK_DoubleBox))->GetCheck())
	{
		theApp.m_bIsDoubleBox = true;
	}
	else
	{
		theApp.m_bIsDoubleBox = false;
	}
	AfxMessageBox("更换物料,请在主界面按停止按钮重新开始检查");
}
